home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / library / tkerror.tcl < prev   
Encoding:
Text File  |  1995-06-08  |  2.1 KB  |  68 lines

  1. # tkerror.tcl --
  2. #
  3. # This file contains a default version of the tkError procedure.  It
  4. # posts a dialog box with the error message and gives the user a chance
  5. # to see a more detailed stack trace.
  6. #
  7. # @(#) tkerror.tcl 1.5 95/02/25 13:54:23
  8. #
  9. # Copyright (c) 1992-1994 The Regents of the University of California.
  10. # Copyright (c) 1994 Sun Microsystems, Inc.
  11. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14.  
  15. # tkerror --
  16. # This is the default version of tkerror.  It posts a dialog box containing
  17. # the error message and gives the user a chance to ask to see a stack
  18. # trace.
  19. # Arguments:
  20. # err -            The error message.
  21.  
  22. proc tkerror err {
  23.     global errorInfo
  24.  
  25.     # Be sure to release any grabs that might be present on the
  26.     # screen, since they could make it impossible for the user
  27.     # to dismiss the error dialog box.
  28.  
  29.     if {[grab current .] != ""} {
  30.     grab release [grab current .]
  31.     }
  32.     set info $errorInfo
  33.     set button [tk_dialog .tkerrorDialog "Error in Tcl Script" \
  34.         "Error: $err" error 0 OK "Skip Messages" "Stack Trace"]
  35.     if {$button == 0} {
  36.     return
  37.     } elseif {$button == 1} {
  38.     return -code break
  39.     }
  40.  
  41.     set w .tkerrorTrace
  42.     catch {destroy $w}
  43.     toplevel $w -class ErrorTrace
  44.     wm minsize $w 1 1
  45.     wm title $w "Stack Trace for Error"
  46.     wm iconname $w "Stack Trace"
  47.     button $w.ok -text OK -command "destroy $w"
  48.     text $w.text -relief sunken -bd 2 -yscrollcommand "$w.scroll set" \
  49.         -setgrid true -width 60 -height 20
  50.     scrollbar $w.scroll -relief sunken -command "$w.text yview"
  51.     pack $w.ok -side bottom -padx 3m -pady 2m
  52.     pack $w.scroll -side right -fill y
  53.     pack $w.text -side left -expand yes -fill both
  54.     $w.text insert 0.0 $info
  55.     $w.text mark set insert 0.0
  56.  
  57.     # Center the window on the screen.
  58.  
  59.     wm withdraw $w
  60.     update idletasks
  61.     set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
  62.         - [winfo vrootx [winfo parent $w]]]
  63.     set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
  64.         - [winfo vrooty [winfo parent $w]]]
  65.     wm geom $w +$x+$y
  66.     wm deiconify $w
  67. }
  68.